home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Devices & Hardware / Drivers / ez_load INIT ƒ / ez_load II.a next >
Encoding:
Text File  |  1991-07-08  |  8.8 KB  |  230 lines  |  [TEXT/MPS ]

  1.  
  2.  
  3.  
  4. ;    © 1989 Apple Computer, Inc.   By Ricardo Batista, Apple Integrated Systems
  5. ;
  6. ;                    ez_load    II    Version 1.0, March 8 1989
  7. ;                                Version 1.1, June 29 1989 unlimited drivers
  8. ;                                Version 1.2, July 8, 1991, fixed utablebase bug when table resized.
  9. ;
  10. ;    This is an INIT that finds an empty slot in the unit table, if there is
  11. ;    no space in the unit table the size of the table is compared to the
  12. ;    pointer of it, because sometimes there is more space but is not counted
  13. ;    and if the space is already there the count of the table is updated.  In
  14. ;    the case where there is no space in the table but the table pointer is
  15. ;    used in full another pointer is made with addtitional space for 16 more
  16. ;    drivers and the old table is copied in the new space and the system globals
  17. ;    updated, once a slot is found the driver is loaded who's name is stored
  18. ;    in a string list resource with id -4033, then it looks at a string list resource
  19. ;    id -4034 for the name of a DATA resource and if there is a name for the DATA
  20. ;    resource this is also loaded.  The id's are changed according to the empty
  21. ;    driver slot found and the driver is opened.  After the driver has been
  22. ;    opened the resources are detached from the resource file.  Notice that for
  23. ;    a driver to stay open, the driver and the DATA resource must have the
  24. ;    sysheap and locked bits set in the resource information.  From then on it
  25. ;    is up to the driver what it does.
  26. ;
  27. ;    This version can load any number of drivers, as many as the STR# resource holds
  28. ;    and their DATA resource if they have any.
  29. ;
  30. ;    INIT resource must be locked
  31.  
  32.     STRING PASCAL
  33.     INCLUDE 'ToolEqu.a'
  34.     INCLUDE 'SysEqu.a'
  35.     INCLUDE 'Traps.a'
  36.     
  37. SCCLockOut        EQU $2600
  38.     
  39. Frame RECORD 4,DECR
  40. return         DS.L 1
  41. A6Link         DS.L 1
  42. theID         DS.W 1
  43. theType     DS.L 1
  44. name         DS.B 256
  45. dtheID         DS.W 1
  46. dtheType     DS.L 1
  47. dname         DS.B 256
  48. counter        DS.W 1
  49. rd6            DS.L 1
  50. rd7            DS.L 1
  51. fSize EQU *
  52.     ENDR
  53.     
  54.     
  55. main    MAIN
  56.     IMPORT ShowINIT
  57.     link a6,#Frame.fSize        ; space for our stack variables
  58.     clr.w Frame.counter(a6)        ; initialize our flag to nothing
  59.     move.l d6,Frame.rd6(a6)        ; save d6
  60.     move.l d7,Frame.rd7(a6)        ; save d7
  61. BeginSearch
  62.     move.w UnitNtryCnt,d2        ; put number of dce's in d2
  63.     subq.w #1,d2                ; subtract one
  64.     move.w d2,d1                ; put in d1 to multiply
  65.     lsl.w #2,d1                    ; multiply by four (shift left 2)
  66.     movea.l UTableBase,a0        ; put unit table base in a0
  67. SrchLoop
  68.     tst.l (a0,d1.w)                ; is there an entry here ?
  69.     beq.s GotSlot                ; yes, take it
  70.     subq.l #4,d1                ; substract four, try next down
  71.     subq.w #1,d2                ; substract one to unit number
  72.     cmpi.w #39,d2                ; are we down to the limit ?
  73.     bgt.s SrchLoop                ; no ? keep trying
  74.     bra Addentries                ; no space huh ? make table bigger
  75. GotSlot
  76.     clr.l -(sp)                    ; space for result
  77.     move.l #'STR#',-(sp)        ; push resource type
  78.     move.w #-4033,-(sp)            ; push id of driver's name to load
  79.     _GetResource                ; get it, handle is in stack
  80.     move.l (sp),-(sp)            ; duplicate it
  81.     _LoadResource                ; make sure it has been loaded
  82.     move.l (sp)+,a0                ; put in a0
  83.     move.l (a0),a0                ; make pointer in a0
  84.     lea Frame.name(a6),a1        ; put destination in a1
  85.     addi.w #1,Frame.counter(a6)    ; add one to our list counter
  86.     jsr GetName                    ; copy the current driver name
  87.     bne end                        ; end of list ? exit...
  88.     clr.l -(sp)                    ; space for result
  89.     move.l #'STR#',-(sp)        ; push resource type
  90.     move.w #-4034,-(sp)            ; push id of driver's data to load
  91.     _GetResource                ; get it, handle is in stack
  92.     move.l (sp),-(sp)            ; duplicate it
  93.     _LoadResource                ; make sure it has been loaded
  94.     move.l (sp)+,a0                ; put in a0
  95.     move.l (a0),a0                ; make pointer in a0
  96.     lea Frame.dname(a6),a1        ; put destination in a1
  97.     jsr GetName                    ; copy the current data name
  98.     bne end                        ; end ? exit
  99.     clr.l -(sp)                    ; space for handle
  100.     move.l #'DRVR',-(sp)        ; push driver type
  101.     pea Frame.name(a6)            ; push name
  102.     _GetNamedResource            ; get it
  103.     move.l (sp)+,d7                ; put driver handle in d7
  104.     beq error                    ; not found, too bad
  105.     move.w ResErr,d0            ; any errors ?
  106.     bne error                    ; it's ok then
  107.     move.l d7,-(sp)                ; push driver handle
  108.     pea Frame.theID(a6)            ; push space fo the id
  109.     pea Frame.theType(a6)        ; push space for type
  110.     pea Frame.name(a6)            ; push space for name
  111.     _GetResInfo                    ; get the resource information
  112.     move.l d7,-(sp)                ; push driver handle again
  113.     move.w d2,-(sp)                ; push the new id
  114.     pea Frame.name(a6)            ; push the name
  115.     _SetResInfo                    ; change the information
  116.     move.b Frame.dname(a6),d0    ; is there a data name to load ?
  117.     beq noData                    ; no ? ok...
  118.     clr.l -(sp)                    ; push zero for handle
  119.     move.l #'DATA',-(sp)        ; push data
  120.     pea Frame.dname(a6)            ; push name of our data
  121.     _GetNamedResource            ; load the resource
  122.     move.l (sp)+,d6                ; put handle in d6
  123.     beq error                    ; not there ? we screwed up
  124.     move.l d6,-(sp)                ; push handle
  125.     pea Frame.dtheID(a6)        ; push space for id of data
  126.     pea Frame.dtheType(a6)        ; push space for type of data
  127.     pea Frame.dname(a6)            ; push space for name of data
  128.     _GetResInfo                    ; get data information
  129.     move.l d6,-(sp)                ; push handle again
  130.     move.w d2,d0                ; put slot id in d0
  131.     lsl.w #5,d0                    ; shift left
  132.     ori.w #$C000,d0                ; make negative, magic number
  133.     move.w d0,-(sp)                ; push new id
  134.     pea Frame.dname(a6)            ; push original name
  135.     _SetResInfo                    ; set the new information
  136. noData
  137.     move.w d2,-(sp)                ; save the unit table id in stack
  138.     clr.w -(sp)                    ; space for reference number
  139.     pea Frame.name(a6)            ; push name of the driver
  140.     _OpenDeskAcc                ; open the driver
  141.     move.w (sp)+,d1                ; refnumber in d1
  142.     move.w (sp)+,d2                ; recover unit table id in d2
  143.     muls.w #-1,d1                ; make a positive value (if negative)
  144.     subi.w #1,d1                ; substract 1
  145.     cmp.w d1,d2                    ; are these the same ?
  146.     bne error                    ; no ? the driver didn't load...
  147.     move.l d7,-(sp)                ; push handle to driver
  148.     _DetachResource                ; now detach it from the resource
  149.     move.b Frame.dname(a6),d0    ; was there a data name loaded ?
  150.     beq end                        ; no ? exit
  151.     move.l d6,-(sp)                ; push handle to driver data
  152.     _DetachResource                ; detach it from the resource
  153.     bra.w BeginSearch            ; do our job again until the end of list
  154. end
  155.     move.l Frame.rd6(a6),d6        ; restore d6
  156.     move.l Frame.rd7(a6),d7        ; restore d7
  157.     unlk a6                        ; destroy our stack variables
  158.     move.w #-4064,-(sp)            ; push id of our icon to show it
  159.     move.w #-1,-(sp)            ; push -1 for moveX
  160.     jsr ShowINIT                ; show the success icon
  161.     rts                            ; return
  162. error
  163.     move.l Frame.rd6(a6),d6        ; restore d6
  164.     move.l Frame.rd7(a6),d7        ; restore d7
  165.     unlk a6                        ; destroy stack frame
  166.     move.w #-4033,-(sp)            ; push id of our error icon to show it
  167.     move.w #-1,-(sp)            ; push -1 for moveX
  168.     jsr ShowINIT                ; show the success icon
  169.     rts                            ; return
  170. Addentries
  171.     movea.l UTableBase,a0        ; put the unit table pointer in a0
  172.     _GetPtrSize                    ; get the size of the pointer in d0
  173.     divu.w #4,d0                ; divide by four
  174.     cmp.w UnitNtryCnt,d0        ; is the pointer bigger that specified ?
  175.     bgt.s AddCount                ; then the space is already there
  176.     add.w #16,d0                ; add space for 16 more slots
  177.     move.w d0,d1                ; save number of table entries in d1
  178.     mulu.w #4,d0                ; make size of entries in bytes
  179.     _NewPtr sys,clear            ; make a new table...
  180.     bne end                        ; no space ? exit
  181.     move.w SR,-(sp)                ; save status register
  182.     move.w #SCCLockOut,SR        ; disable interrupts
  183.     movea.l a0,a1                ; put address of new unit table in a1
  184.     movea.l UTableBase,a0        ; put original table in a0
  185.     move.w UnitNtryCnt,d0        ; put original table count in d0
  186.     mulu.w #4,d0                ; get the byte size
  187.     _BlockMove                    ; copy into the new table
  188.     _DisposPtr                    ; dispose of the old table
  189.     move.w d1,UnitNtryCnt        ; save new number of entries in table
  190.     move.l a1,UTableBase        ; save the new table base pointer
  191.     move.w (sp)+,SR                ; recover the status register
  192.     bra BeginSearch                ; this time we'll find a slot
  193. AddCount
  194.     move.w d0,UnitNtryCnt        ; add the unused slots to the count
  195.     bra BeginSearch                ; go find a slot again
  196.     
  197.     DC.B '© 1989 Apple Computer, Inc.  By Ricardo Batista'
  198.     ALIGN
  199.     
  200. GetName
  201.     movem.l d1-d2,-(sp)            ; save registers we will use
  202.     move.w (a0),d0                ; put number of list entries in d0
  203.     cmp.w Frame.counter(a6),d0    ; d0- count, d0 < 0 end of list
  204.     blt ListEnd                    ; end of the list, no more
  205.     move.w Frame.counter(a6),d0    ; put the number of item we want in d0
  206.     adda.l #2,a0                ; point to first string len byte
  207.     moveq #0,d2                    ; clear d2, d0 still has string number we want
  208. FindName
  209.     addi.w #1,d2                ; add one to current string we point to counter
  210.     cmp.w d0,d2                    ; is this the string number we want ?
  211.     beq.s CopyName                ; if so, then go copy the name and return
  212.     moveq #0,d1                    ; clear d1
  213.     move.b (a0),d1                ; put string len byte in d1
  214.     addi.w #1,d1                ; add one for the lenght
  215.     adda.l d1,a0                ; now a0 points to the next string
  216.     bra.s FindName                ; go see if this is the one we want
  217. CopyName
  218.     moveq #30,d0                ; at the most 30 bytes for data name
  219.     _BlockMove                    ; now we have the data name
  220.     movem.l (sp)+,d1-d2            ; recover registers
  221.     moveq #0,d0                    ; set Z flag, list still valid
  222.     rts                            ; return to caller
  223. ListEnd
  224.     movem.l (sp)+,d1-d2            ; recover registers
  225.     moveq #1,d0                    ; clear Z flag, end of list
  226.     rts                            ; return to caller
  227.     ENDMAIN
  228.     
  229.     END
  230.